package org.llc.gof.structure.proxy.dynamic.basic1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author harvey
 */
public class MyInvocationHandler implements InvocationHandler {

    private Object target;

    public MyInvocationHandler(Object _obj) {
        this.target = _obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        Object result;
        this.before();
        result = method.invoke(this.target, args);
        this.after();
        return result;
    }

    public void before() {
        System.out.println("执行before方法");
    }

    public void after() {
        System.out.println("执行after方法");
        this.before();
    }

}
